<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<script type="text/javascript" src="<?php echo STATIC_DOMAIN;?>js/highcharts/js/highcharts.src.js"></script>
<script type="text/javascript" src="<?php echo STATIC_DOMAIN;?>js/highcharts/js/modules/exporting.src.js"></script>
<script type="text/javascript" src="<?php echo STATIC_DOMAIN;?>js/highcharts/js/themes/grid.js"></script>
<div class="middle padtop10 myclear">
	<div class="page-content">
		<h2>
			Zone report
		</h2>
		
		<table class="martop10" width="100%" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td class="pad10" width="28%" style="border: 1px solid #ccc;">
					<b>Tổng số zones đang chạy: </b> 
					<a href="<?php echo site_url('zone/view_type') . '?t=0&s=-1&d=' . $view_date; ?>" style="font-size: 14px; font-weight: bold; color:#ff6600;"><?php echo $total_active; ?></a>
				</td>
				
				<td class="padleft20 padtop10" style="border: 1px solid #ccc;">
					<p class="padbottom10">
						<input type="text" value="<?php echo $view_date; ?>" id="date" class="input-time"/>
					</p>
					<p class="padbottom10">
						<b>Tổng số zones hiệu quả: </b> <span style="font-size: 14px; padding-left: 10px;font-weight: bold; color:#ff6600;"><?php echo $total_good; ?></span> (Realclick &gt;= <?php echo $bad_limit; ?> click)
					</p>
					<p class="padbottom10">
						<b>Tổng số zones không hiệu quả: </b> <span style="font-size: 14px; padding-left: 10px;font-weight: bold; color:#ff6600;"><?php echo $total_bad; ?></span> (Realclick &lt; <?php echo $bad_limit; ?> click)
					</p>
					<p class="padbottom10">
						<b>Tổng số zones không có report: </b> <span style="font-size: 14px; padding-left: 10px; font-weight: bold; color:#ff6600;"><?php echo $total_no_report; ?></span>
					</p>
					
					<div id="Zone_Pie_Chart" class="chart"></div>
				</td>
			</tr>
			
			
			<tr>
				<td colspan="2" class="pad10" style="border: 1px solid #ccc;">
					<b>Tổng số zones ngừng chạy: </b> <a href="<?php echo site_url('zone/view_delete');?>" style="font-size: 14px; padding-left: 10px;font-weight: bold; color:#ff6600;"><?php echo $total_deleted; ?></a>
				</td>
			</tr>
		</table>		
	</div>
</div>
<script type="text/javascript">
	var addCommasNumber=function addCommas(nStr)
	{
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	};
	var chart1;
	
	$(document).ready(function() {
		<?php if($zone_chart!='')
	   	{ 
   		?>
	   	chart1 = new Highcharts.Chart({
			  chart: {
				 renderTo: 'Zone_Pie_Chart',
				 plotBackgroundColor: null,
				 plotBorderWidth: null,
				 plotShadow: true
			  },
			  title: {
				 text: ''
			  },
			  tooltip: {
				 formatter: function() {
					return '<b>'+ this.point.name +'</b>:  '+ addCommasNumber(this.point.vote)+' zones, Chiếm:'+ this.y +' %';
				 }
			  },
			  plotOptions: {
				 pie: {
					allowPointSelect: true,
					cursor: 'pointer',
					dataLabels: {
					   enabled: true,
					   color: Highcharts.theme.textColor || '#000000',
					   connectorColor: Highcharts.theme.textColor || '#000000',
					   formatter: function() {
						  return '<b>'+ this.point.name +'</b><br/>  '+ addCommasNumber(this.point.vote)+' zones, - Chiếm '+ this.y +' %';
					   }
					},
					showInLegend: true
				 }
			  },
			   series: [{
				 type: 'pie',
				 name: '',
				 data: [
					<?php echo $zone_chart;?>
				 ]
			  }],
			  exporting: {
				enabled: false
			  }
	   });
		<?php 
	   	}
	  	else
	   	{
   		?>
	   		$('#Zone_Pie_Chart').html('Chưa có dữ liệu trả về');
	   	<?php
	   	}
	   	?>
	});
	$('#date').DatePicker({
		format: 'd-m-Y',
		date: '<?php echo date('d-m-Y');?>',
		current: '<?php echo $view_date; ?>',
		position: 'right',
		onChange: function(formated, dates) 
		{
			$('#date').val(formated);
			$('#date').DatePickerHide();
			window.location = '/admin/zone/dashboard/?d=' + formated;
		}
	});
</script>